package demo.xlj.yuyi.studentapp.utils;

import android.app.Activity;
import android.content.Intent;

import demo.xlj.yuyi.studentapp.R;

/**
 * 作者：项路俊 on 2018/2/26 0026
 * 邮箱：ThanksForCode@gmail.com
 * 介绍：Activity的跳转帮助类
 */

public class ActivityUtil {


    /**
     * 打开一个新的Activity时候调用,不带有返回值
     */
    public static void openActivityFromBottomToTop(Activity context, Class<?> cls){
        Intent intent = new Intent(context,cls);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_open_enter,R.anim.activity_open_out);
    }

    /**
     * 打开一个新的Activity时候调用，带有返回值
     */
    public static void openActivityForResultFromBottomToTop(Activity context, Class<?> cls,int code){
        Intent intent = new Intent(context,cls);
        context.startActivityForResult(intent,code);
        context.overridePendingTransition(R.anim.activity_open_enter,R.anim.activity_open_out);
    }

    /***
     * 关闭一个activity时候调用，只是添加动画
     */
    public static void closeActivityFromTopToBottom(Activity context){
        context.overridePendingTransition(R.anim.activity_close_enter,R.anim.activity_close_out);
    }

    /**
     * 打开一个新的Activity时候调用,不带有返回值
     */
    public static void openActivityFromLeftToRight(Activity context, Class<?> cls){
        Intent intent = new Intent(context,cls);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_open_slide_enter,R.anim.activity_open_slide_out);
    }

    /**
     * 打开一个新的Activity时候调用，带有返回值
     */
    public static void openActivityForResultFromLeftToRight(Activity context, Class<?> cls,int code){
        Intent intent = new Intent(context,cls);
        context.startActivityForResult(intent,code);
        context.overridePendingTransition(R.anim.activity_open_slide_enter,R.anim.activity_open_slide_out);
    }

    /***
     * 关闭一个activity时候调用，只是添加动画
     */
    public static void closeActivityRightToLeft(Activity context){
        context.overridePendingTransition(R.anim.activity_close_slide_enter,R.anim.activity_close_slide_out);
    }

    /**
     * 打开一个新的Activity时候调用,不带有返回值,传一个值
     */
    public static void openActivityFromLeftToRightByResult(Activity context, Class<?> cls,String key_one,String value_one){
        Intent intent = new Intent(context,cls);
        intent.putExtra(key_one,value_one);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_open_slide_enter,R.anim.activity_open_slide_out);
    }
    /*
    *  打开一个新的activity，带有多个值
    * */

    public static void openActivityFromLeftToRightByMoreResuslt(Activity context,Class<?> cls,String [] key,String [] value){
        Intent intent = new Intent(context,cls);
        for (int i = 0; i < key.length; i++) {
            intent.putExtra(key[i],value[i]);
        }
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_open_slide_enter,R.anim.activity_open_slide_out);
    }
}
